﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using DataLayer.Controller;

public partial class provider_HistoryPayment : cGlobal
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //grvDocumento.DataSource = ProviderController.GetHistory(Request.Params["NIT"]);
            //this.loadGrid("890903937-00");
            if (Request.QueryString["NIT"] != null)
            {
                this.hdnNIT.Value = Request.QueryString["NIT"].ToString();
                this.loadGrid(this.hdnNIT.Value.ToString());
            }
            
        }
    }

    private void loadGrid(string nit)
    {
        DataTable dtt = ProviderController.GetHistory(nit);
        grvDocumento.DataSource = dtt;
        grvDocumento.DataBind();

        //Se guarda en session la tabla de los resultados, para poder filtrar
        Session["VIEWHISTORYPAYMENT"] = dtt;
    }

    protected void grvDocumento_RowDataBound(object sender, Obout.Grid.GridRowEventArgs e)
    {
        if (e.Row.RowType == Obout.Grid.GridRowType.DataRow)
        {            
            HyperLink lnkVerDocumento = (HyperLink)e.Row.Cells[7].Controls[0].Controls[0].Controls[0].Controls[0].Controls[1];
            //lnkVerDocumento.NavigateUrl = "Javascript:openShadowbox('" + urlPortal + "/services/Flow.aspx?idService=" + DataBinder.Eval(e.Row.DataItem, "idServicioSF").ToString().Trim() + "','iframe','Estado del servicio',680,425);";

            HyperLink lnkVerFactura = (HyperLink)e.Row.Cells[8].Controls[0].Controls[0].Controls[0].Controls[0].Controls[1];
            lnkVerFactura.NavigateUrl = "Javascript:openShadowbox('" + ConfigurationManager.AppSettings["urlPortal"] + "/provider/DocSupport.aspx?NoFactura=" + DataBinder.Eval(e.Row.DataItem, "NUMERO_FACTURA").ToString().Trim() + "','iframe','Documentos de Soporte',590,400);";            
        }
    }

    protected void btnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect(urlPortal + "provider/StateAccount.aspx?NIT=" + Request.Params["NIT"].ToString() + "&usrNombre=" + Request.Params["usrNombre"].ToString());
    }

    /// <summary>
    /// Configura las opciones que se utilizaran para exportar la grilla
    /// </summary>
    private void configExport()
    {
        this.grvDocumento.ExportingSettings.AppendTimeStamp = false;
        this.grvDocumento.ExportingSettings.ExportAllPages = true;
        this.grvDocumento.ExportingSettings.ExportHiddenColumns = true;
        this.grvDocumento.ExportingSettings.FileName = "EstadoCuenta";
        this.grvDocumento.ExportingSettings.KeepColumnSettings = false;
        this.grvDocumento.ExportingSettings.ExportTemplates = true;

        this.grvDocumento.ExportingSettings.ColumnsToExport = null;
    }

    #region "Filtros de la grilla"

    protected void btnBuscarGrilla_Click(object sender, ImageClickEventArgs e)
    {
        if (string.IsNullOrEmpty(this.txtContiene.Text.Trim()))
            return;

        if (Session["VIEWHISTORYPAYMENT"] != null)
        {
            DataTable dtt = (DataTable)Session["VIEWHISTORYPAYMENT"];
            string columna = this.hdnColumnaSeleccionada.Value.ToString();

            DataView dw = dtt.DefaultView;
            dw.RowFilter = columna + " LIKE '%" + this.txtContiene.Text.Trim() + "%'";
            dtt = dw.ToTable();

            this.grvDocumento.DataSource = dtt;
            this.grvDocumento.DataBind();
            Session["VIEWHISTORYPAYMENT"] = dtt;

            this.txtContiene.Text = string.Empty;
        }
    }

    protected void lnkAscendente_Click(object sender, EventArgs e)
    {
        if (Session["VIEWHISTORYPAYMENT"] != null)
        {
            DataTable dtt = (DataTable)Session["VIEWHISTORYPAYMENT"];
            string columna = this.hdnColumnaSeleccionada.Value.ToString();

            DataView dw = dtt.DefaultView;
            dw.Sort = columna + " ASC";
            dtt = dw.ToTable();

            this.grvDocumento.DataSource = dtt;
            this.grvDocumento.DataBind();
            Session["VIEWHISTORYPAYMENT"] = dtt;
        }
    }

    protected void lnkDescendente_Click(object sender, EventArgs e)
    {
        if (Session["VIEWHISTORYPAYMENT"] != null)
        {
            DataTable dtt = (DataTable)Session["VIEWHISTORYPAYMENT"];
            string columna = this.hdnColumnaSeleccionada.Value.ToString();

            DataView dw = dtt.DefaultView;
            dw.Sort = columna + " DESC";
            dtt = dw.ToTable();

            this.grvDocumento.DataSource = dtt;
            this.grvDocumento.DataBind();
            Session["VIEWHISTORYPAYMENT"] = dtt;
        }
    }

    protected void lnkSinFiltro_Click(object sender, EventArgs e)
    {
        this.loadGrid(this.hdnNIT.Value.ToString());
    }

    #endregion


}
